package com.demo6;

public class GirlFriendTest {
    public static void main(String[] args) {
        //1.定义数组存储女朋友的对象
        GirlFriend[] arr = new GirlFriend[4];
        //2.创建女朋友对象
        GirlFriend girlFriend1 = new GirlFriend("小诗诗", 18, "萌妹子", "吃零食");
        GirlFriend girlFriend2 = new GirlFriend("小丹丹", 19, "萌妹子", "玩游戏");
        GirlFriend girlFriend3 = new GirlFriend("小慧慧", 20, "萌妹子", "学习");
        GirlFriend girlFriend4 = new GirlFriend("小丽丽", 21, "憨妹子", "睡觉");
        //3.把对象添加到数组当中
        arr[0]=girlFriend1;
        arr[1]=girlFriend2;
        arr[2]=girlFriend3;
        arr[3]=girlFriend4;
        //4.求和
        int sum=0;
        for (int i = 0; i < arr.length; i++) {
            //i 索引 arr[i] 元素
            GirlFriend girlFriend = arr[i];
            sum+=girlFriend.getAge();
        }

        //5.求平均值
        int avg=sum/arr.length;

        //6.判断
        int count=0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriend girlFriend = arr[i];
            if(girlFriend.getAge()<avg){
                count++;
                System.out.println("名字为:"+girlFriend.getName()+"\t"+
                        "年龄为:"+girlFriend.getAge()+"\t"+
                        "性格为:"+girlFriend.getGender()+"\t"+
                        "爱好为:"+girlFriend.getHobby());
            }
        }
        System.out.println("count="+count);
    }
}
